package love.bot.forli.group.review.handler;

import lombok.extern.slf4j.Slf4j;
import love.bot.forli.group.review.bean.Result;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 异常拦截器
 * @author Kontori
 */
@RestControllerAdvice
@Slf4j
public class WebExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public Result<String> exceptionHandler(HttpServletRequest request, Exception e) {
        log.error("运行时异常: Request Url: {}, exception: {}", request.getRequestURL(), e.toString());
        e.printStackTrace();
        return Result.fail(e.getMessage());
    }

}
